import Vue from "vue";
import App from "./App.vue";
import router from "./router/shouwei.js";
import store from "./store";
//以 vue 插件的方式完整引入 vant 组件
// import Vant, { Lazyload } from "vant";
// import "vant/lib/index.css";
import "amfe-flexible/index.js";
import { rTimes, formDate } from "@/utils/date-time.js";
console.log(rTimes(Date.now()), "相对时间");
import {
  Dialog,
  Button,
  Tabbar,
  TabbarItem,
  Form,
  Field,
  NavBar,
  Toast,
  Tabs,
  Tab,
  List,
  Lazyload,
  CellGroup,
  Cell,
  Icon,
  Grid,
  GridItem,
  Popup,
  Row,
  Col,
  Tag,
  Image,
  Divider,
  PullRefresh,
  ActionSheet,
  Loading,
  Search
} from 'vant';
const vants = [
  Dialog,
  Button,
  Tabbar,
  TabbarItem,
  Form,
  Field,
  NavBar,
  Toast,
  Tabs,
  Tab,
  List,
  Lazyload,
  CellGroup,
  Cell,
  Icon,
  Grid,
  GridItem,
  Popup,
  Row,
  Col,
  Tag,
  Image,
  Divider,
  PullRefresh,
  ActionSheet,
  Loading,
  Search
];
//循环引入
vants.map(item => {
  Vue.use(item);
});

//定义一个全局过滤器
Vue.filter("rTime", rTimes); // 注意  函数里要有 return 返回我们处理的结果  {{xxx | rTime }}
Vue.prototype.$formDate = formDate;

Vue.config.productionTip = false;

//注册eventBus
Vue.prototype.$eventBus = new Vue();

// Vue.use(Vant);
//使用懒加载
// Vue.use(Lazyload);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

// 在main.js中添加如下代码  此代码是采用的 5+ Runtime中的plus对象
document.addEventListener("plusready", function () {
  var webview = window.plus.webview.currentWebview();
  window.plus.key.addEventListener("backbutton", function () {
    webview.canBack(function (e) {
      if (e.canBack) {
        webview.back();
      } else {
        // webview.close(); //hide,quit
        // plus.runtime.quit();
        // 首页返回键处理
        // 处理逻辑：1秒内，连续两次按返回键，则退出应用；
        var first = null;
        window.plus.key.addEventListener(
          "backbutton",
          function () {
            // 首次按键，提示‘再按一次退出应用’
            if (!first) {
              first = new Date().getTime();
              setTimeout(function () {
                first = null;
              }, 1000);
            } else {
              if (new Date().getTime() - first < 1500) {
                window.plus.runtime.quit();
              }
            }
          },
          false
        );
      }
    });
  });
});
